// pages/Apply/Apply.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgdown: app.maImgburl.webUrl +'/down.png',
    imgup: app.maImgburl.webUrl + '/up.png',
    PickerArray: ['一般共同財產制', '取得公共財產制', '分別財產制', '取得財產分享制'],
    MarriagePropertyType: '',
    radioitems: [{ name: '已婚', value: '1' }, { name: '未婚', value: '0' }],
    showSpouse: true,
    moreInfo:true,
    lesshow: true,
    ApplyName: "",
    ApplyFirstName: "",
    Phone: "",
    PropertyAddress: "",
    ContractPrice: "",
    LoanAmount: "",
    IDNumber:"",
    LiveAddress: "",
    Company: "",
    Duties:"",
    Years:"",
    InCome:"",
    MaritalStatus: "",
    SpouseName:"",
    SpouseIDNumber:"",
    FamilyIncome:""
  },

  moreshowTap:function(e){
    this.setData({
      moreInfo:false,
      lesshow:false,
      moreshow:true,
    })
  },
  lesshowTap: function (e) {
    this.setData({
      moreInfo: true,
      lesshow: true,
      moreshow: false,
    })
  },
  
 
  

  

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  ApplyNameInput: function (e) {
    
    this.setData({
      ApplyName: e.detail.value
    })
  },
  ApplyFirstNameInput: function (e) {
  
    this.setData({
      ApplyFirstName: e.detail.value
    })
  },
  PhoneInput: function (e) {
    this.setData({
      Phone: e.detail.value
    })
  },
  PropertyAddressInput: function (e) {
    this.setData({
      PropertyAddress: e.detail.value
    })
  },
  ContractPriceInput:function(e){
    this.setData({
      ContractPrice: e.detail.value
    })
  },
  LoanAmountInput: function (e) {
    this.setData({
      LoanAmount: e.detail.value
    })
  },
  IDNumberInput:function(e){
    this.setData({
      IDNumber: e.detail.value
    }) 
  },
  LiveAddressInput:function(e){
    this.setData({
      LiveAddress: e.detail.value
    }) 
  },
  CompanyInput:function(e){
    this.setData({
      Company: e.detail.value
    }) 
  },
  DutiesInput:function(e){
    this.setData({
      Duties: e.detail.value
    }) 
  },
  YearsInput:function(e){
    this.setData({
      Years: e.detail.value
    }) 
  },
  InComeInput:function(e){
    this.setData({
      InCome: e.detail.value
    }) 
  },
  radioChange: function (e) {
    
    if (e.detail.value == 1) { //已婚
      this.setData({
        MaritalStatus: e.detail.value,
        showSpouse: false
      })
    }
    else {
      this.setData({
        MaritalStatus: e.detail.value,
        showSpouse: true
      })
    }
    console.log(e)
  },
  bindPickerChange: function (e) {
    var that = this
    /*console.log('picker发送选择改变，携带值为', that.data.array[e.detail.value])*/
    this.setData({
      MarriagePropertyType: that.data.PickerArray[e.detail.value]
    })
  },
  SpouseNameInput:function(e){
    this.setData({
      SpouseName: e.detail.value
    })
  },
  SpouseIDNumberInput:function(e){
    this.setData({
      SpouseIDNumber: e.detail.value
    })  
  },
  FamilyIncomeInput:function(e){
    this.setData({
      FamilyIncome: e.detail.value
    })  
  },
  SvaeNewApply: function (e) {
    var that=this;
    if (that.data.ApplyName.trim().length==0)
    {
      wx.showModal({
        showCancel:false,
        title: '警告',
        content: '請填寫申請人姓',
      })
      return false;
    }
    if (that.data.ApplyFirstName.trim().length == 0) {
      wx.showModal({
        showCancel: false,
        title: '警告',
        content: '請填寫名字',
      })
      return false;
    }
    if (that.data.Phone.trim().length == 0) {
      wx.showModal({
        showCancel: false,
        title: '警告',
        content: '請填寫電話號碼',
      })
      return false;
    }
    if (that.data.PropertyAddress.trim().length == 0) {
      wx.showModal({
        showCancel: false,
        title: '警告',
        content: '請填寫購買物業地址',
      })
      return false;
    }
    if (that.data.ContractPrice.trim().length == 0) {
      wx.showModal({
        showCancel: false,
        title: '警告',
        content: '請填寫購買合約樓價',
      })
      return false;
    }
    if (that.data.LoanAmount.trim().length == 0) {
      wx.showModal({
        showCancel: false,
        title: '警告',
        content: '請填寫申請貸款金額',
      })
      return false;
    }
    wx.request({
      url: app.macauweburl.webUrl+'/api/AppApply/SaveApply',
     // url:+'/api/AppApply/SaveApply',
      method: 'POST',
      data: {
        ApplyName: this.data.ApplyName,
        ApplyFirstName: this.data.ApplyFirstName,
        Phone: this.data.Phone,
        PropertyAddress: this.data.PropertyAddress,
        ContractPrice:this.data.ContractPrice,
        LoanAmount:this.data.LoanAmount,
        IDNumber: this.data.IDNumber,
        LiveAddress: this.data.LiveAddress,
        Company: this.data.Company,
        Duties: this.data.Duties,
        Years: this.data.Years,
        InCome: this.data.InCome,
        MaritalStatus: this.data.MaritalStatus,
        SpouseName: this.data.SpouseName,
        SpouseIDNumber: this.data.SpouseIDNumber,
        FamilyIncome: this.data.FamilyIncome,
        MarriagePropertyType: this.data.MarriagePropertyType,
      },
      header: {
        'content-type': "application/x-www-form-urlencoded" // 後台不使用解釋json的方式話。使用此方法進行
      },
      success: function (res) {
        if (res.data =="Success")
        {
          wx.showToast({
            title: '申請成功',
            icon: 'success',
            duration: 1000
          })
          setTimeout(function(){
             wx.redirectTo({
               url: '/pages/Home/Home',
             })
          },1000) 
        }
      }
    })
  }
})